# # -*- coding: utf-8 -*-

import re


def set_val(json_obj, path, val):
    path_arr = []
    for _, k, i in re.findall(r'((\w+)(\[\d+\])?\.?)', path):
        path_arr.append(k)
        if i: path_arr.append(int(i[1:-1]))

    def _get(c_path, curr=json_obj):
        if len(c_path) == 1:
            curr[c_path[0]] = val
        else:
            _get(c_path[1:], curr[c_path[0]])
    _get(path_arr)
